package cn.xiehang.SoundSight;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTabHost;

@SuppressLint("InflateParams")
public class TestFragmentActivity extends FragmentActivity {
    private static final String TAG = "TestFragmentActivity";
    private Bundle mBundle = new Bundle();
    private FragmentTabHost mTabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_fragment);

        mBundle.putString("tag", TAG);
        mTabHost = findViewById(android.R.id.tabhost); // 使用 android.R.id.tabhost
        mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); // 使用 android.R.id.tabcontent

//        // 添加 Tab
//        mTabHost.addTab(getTabView(R.string.menu_first, R.drawable.tabbar_first_selector), FirstFragment.class, mBundle);
//        mTabHost.addTab(getTabView(R.string.menu_second, R.drawable.tabbar_second_selector), SecondFragment.class, mBundle);
//        mTabHost.addTab(getTabView(R.string.menu_third, R.drawable.tabbar_third_selector), ThirdFragment.class, mBundle);

        // 隐藏 Tab 之间的分隔线
        mTabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }

    private TabSpec getTabView(int textId, int imgId) {
        String text = getResources().getString(textId);
        Drawable drawable = getResources().getDrawable(imgId);

        // 设置图标大小（例如 48x48 像素）
        int iconSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics());
        drawable.setBounds(0, 0, iconSize, iconSize);

        // 加载 Tab 标签布局
        View tabbarItem = getLayoutInflater().inflate(R.layout.tabbar_item, null);
        TextView tvItem = tabbarItem.findViewById(R.id.tv_item);
        tvItem.setText(text);
        tvItem.setCompoundDrawables(null, drawable, null, null); // 设置图标

        // 创建 TabSpec
        TabSpec spec = mTabHost.newTabSpec(text).setIndicator(tabbarItem);
        return spec;
    }


}